package edu.hubu.work01.Service.impl;

import edu.hubu.work01.entity.Feed;
import edu.hubu.work01.mapper.FeedMapper;
import edu.hubu.work01.Service.FeedService;
import edu.hubu.work01.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FeedServiceImpl implements FeedService {
    @Autowired
    private FeedMapper feedMapper;
    public ResultVO addFeed(Feed feed){
        int i = feedMapper.insertFeed(feed);
        if (i > 0) {
            return new ResultVO(200, "添加成功！", null);
        } else {
            return new ResultVO(500, "添加失败！", null);
        }
    }

    public ResultVO buyFeed(int feedId,int weight)
    {
        int i = feedMapper.buy(feedId,weight);
        if (i>0) {
            return new ResultVO(200, "购入", null);
        } else {
            return new ResultVO(500, "失败", null);
        }
    }

    public ResultVO listF(){
        List<Feed> feeds = feedMapper.listFeed();
        if(feeds != null)
        {
            return new ResultVO(200, "查询到", feeds);
        } else {
            return new ResultVO(500, "没有", feeds);
        }
    }
}

